const BASE_URL_TEST='http://192.168.20.213:8989'

export const getRolesPage =async()=>{
  try{
    const res=await fetch(BASE_URL_TEST + '/roles/page?pageNum=1&pageSize=10')
    return res.json()
  }catch(error){
    console.log(error + 'error');
  }
}

export const postRoles=async()=>{
  const myHeaders=new Headers()
  myHeaders.append('Content-Type','application/json')
  // myHeaders.append('Authorization','eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySW5mbyI6eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoiYWRtaW4iLCJuaWNrbmFtZSI6Iuezu-e7n-euoeeQhuWRmGFkbWluIiwiZGVwdElkIjoxLCJyb2xlcyI6IkFETUlOIn0sImlzcyI6ImR5czYyMzAiLCJleHAiOjE3MzIwMTU0ODMsIm5iZiI6MTczMTk3OTQ4MywiaWF0IjoxNzMxOTc5NDgzfQ.6aglo9EBRoknFCP1JRIcvtRcBdC1TihxxmOrlUwtiCA')
  const newRole={
    name:'秋谷风',
    code:'114',
    sort:514,
    status:1,
    dataScope:1
    // id:200,
    // name:'张振中',
    // code:2,
    // sort:202,
    // status:202,
    // dataScope:202
  }
  const resquestOptions:RequestInit={
    method:'POST',
    headers:myHeaders,
    body:JSON.stringify(newRole)
  }
  const res=await fetch(BASE_URL_TEST + '/roles',resquestOptions)
  if(res.ok){
    return res.json()
  }
}

export const putRoles=()=>{
  const myHeaders=new Headers()
  myHeaders.append('Content-Type','application/json')
  const raw={
    name:'秋谷风',
    code:'114',
    sort:514,
    status:1,
    dataScope:1
  }
  const resquestOptions={
    method:'PUT',
    headers:myHeaders,
    body:JSON.stringify(raw)
  }
  fetch(BASE_URL_TEST + '/roles/23484',resquestOptions)
  .then((response)=>response.text())
  .then((result)=>console.log(result))
  .then((error)=>console.log(error + 'error'))
}

export const deleteRoles=()=>{
  const resquestOptions={
    method:'DELETE'
  }
  fetch(BASE_URL_TEST + '/roles/23484',resquestOptions)
  .then((response)=>response.text())
  .then((result)=>console.log(result))
  .then((error)=>console.log(error + 'error'))
}

export const patchRoles=()=>{
  const resquestOptions={
    method:'PATCH'
  }
  fetch(BASE_URL_TEST + '/roles/23484/status?status=2',resquestOptions)
  .then((response)=>response.text())
  .then((result)=>console.log(result))
  .then((error)=>console.log(error + 'error'))
}
